Easy reporting with Quarto

Author

David Granjon (cynkra GmbH)

library(ggplot2)
library(palmerpenguins)

Welcome to Quarto®

An open-source scientific and technical publishing system 1

Various output formats

  • Reports.
  • Presentations.
  • Books.
  • Websites, blogs.
  • Dashboards.

Various languages

R, Python, julia, observable.

How Quarto works

Is is complex: anatomy of a qmd file

---
title: "Hello, Quarto"
format: 
  html:
    code-fold: true
    code-tools: true
    code-link: true
  pdf:
    geometry: 
      - top=30mm
      - left=30mm
editor: visual
---

## This is an example

A super plot

```{r}
#| label: scatterplot
#| echo: true

ggplot(mpg, aes(x = hwy, y = cty, color = cyl)) +
  geom_point(alpha = 0.5, size = 2) +
  scale_color_viridis_c() +
  theme_minimal()
```

## A second title

Markdown basics (1)

Headings

# Heading 1
## Heading 2
...
###### Heading 6

Images

![Caption](<IMAGE_PATH>){fig-align="center|left|right" ...}

Code

```{r}
#| echo: false
#| fig-cap: "Air Quality"
#| label: code label
#| eval: true

library(tidyverse)
penguins %>% 
  group_by(species) %>% 
  summarize(across(where(is.numeric), mean, na.rm = TRUE))
```

Markdown basics (2)

Equations

Inline

$\lambda$

Display

$$
\frac{dN}{dt} = rN \left( 1 - \frac{N}{K} \right).
$$

Code annotations

Code


```r
library(tidyverse)
library(palmerpenguins)
penguins |>                                      # <1>
  mutate(                                        # <2>
    bill_ratio = bill_depth_mm / bill_length_mm, # <2>
    bill_area  = bill_depth_mm * bill_length_mm  # <2>
  )                                              # <2>
```
1. Take `penguins`, and then,
2. add new columns for the bill ratio and bill area.

Result

library(tidyverse)
library(palmerpenguins)
1penguins |>
2  mutate(
    bill_ratio = bill_depth_mm / bill_length_mm,
    bill_area  = bill_depth_mm * bill_length_mm
  )
1
Take penguins, and then,
2
add new columns for the bill ratio and bill area.

Code options

Code


```r
#| code-fold: true
#| code-summary: "Show the code"
1+1
```

Result

Show the code
1 + 1
[1] 2

Output location

Add #| output-location: column to you code options.


```r
#| output-location: column
#| fig-width: 6
#| fig-height: 4
ggplot(penguins, 
       aes(x = bill_length_mm, 
           y = bill_depth_mm, 
           color = species)) +
  geom_point()
```

. . .


ggplot(
  penguins,
  aes(x = bill_length_mm, y = bill_depth_mm, color = species)
) +
  geom_point()
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).

Diagrams

Quarto supports mermaid.js

Code


```mermaid
%%| fig-width: 6.5
flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
```

Result

flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}

Caching computations

---
title: "My Document"
execute: 
  cache: true
---

```{r}
#| cache: true
# code for lengthy computation...
```

Exercise 1: Quarto manuscripts

Complete exercise 3 at https://rsc.cynkra.com/e2m2-workshop/exercises.html.

Exercise 2: Quarto websites

Complete exercise 4 at https://rsc.cynkra.com/e2m2-workshop/exercises.html.

Dashboards

---
title: "Old Faithful"
format: dashboard
server: shiny
---

## {.sidebar}
```{r}
sliderInput("bins", "Number of bins:", 
            min = 1, max = 50, value = 30)
plotOutput("distPlot")
```

## Column

```{r}
#| context: server
output$distPlot <- renderPlot({
  x <- faithful[, 2]  # Old Faithful Geyser data
  bins <- seq(min(x), max(x), length.out = input$bins + 1)
  hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
```

Footnotes

  1. This workshop is fully made with Quarto!↩︎